package org.lilred.ui;

import org.lilred.ui.theme.Theme;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;

public class ClickableThemedLabelField extends ClickableThemedField {
	private int padding = 0; 
	String labelText;

	public ClickableThemedLabelField(String label, Theme unfocusTheme, Theme focusTheme) {
		this(label, 0, unfocusTheme, focusTheme, 0);
	}

	public ClickableThemedLabelField(String label, Theme unfocusTheme, Theme focusTheme, long style) {
		this(label, 0, unfocusTheme, focusTheme, style);
	}	
	
	public ClickableThemedLabelField(String label, int padding, Theme unfocusTheme, Theme focusTheme) {
		this(label, padding, unfocusTheme, focusTheme, 0);
	}

	public ClickableThemedLabelField(String label, int padding, Theme unfocusTheme, Theme focusTheme, long style) {
		super(unfocusTheme, focusTheme, style);
		this.padding = padding;
		this.labelText = label;
	}	

	public void setText(String label) {
		this.labelText = label;
		invalidate();
	}
	
	public void setPadding(int padding) { this.padding = padding; }
	public int getPadding() { return padding; }
	
	public int getPreferredWidth() { return getFont().getAdvance(labelText) + 2 * padding; }
	public int getPreferredHeight() { return getFont().getHeight() + 2 * padding; }

	protected void layout(int width, int height) {
		if ((getStyle() & Field.USE_ALL_WIDTH) == Field.USE_ALL_WIDTH) setExtent(width, getPreferredHeight());
		else setExtent(getPreferredWidth(), getPreferredHeight());
	}

	protected void paint(Graphics g) {
		super.paint(g);
		g.drawText(labelText, padding, padding);
	}

	public Theme getActiveTheme() {
		return null;
	}
}
